package com.sinopec.basemodule.widget.myedittext.clean

import android.content.Context
import android.util.AttributeSet
import com.sinopec.basemodule.widget.myedittext.ShowEndIconEditText

/**
 * 类描述：右侧是清楚按钮的布局 <br/>
 * 创建人：lwj<br/>
 * 创建时间：2020/4/10 16:56 <br/>
 */
open class CleanEditText :
        ShowEndIconEditText {
    constructor(context: Context) : this(context, null)

    constructor(context: Context, attrs: AttributeSet?) : super(
            context,
            attrs
    ) {
        setOnclickListener()
    }

    constructor(
            context: Context,
            attrs: AttributeSet?,
            defStyleAttr: Int
    ) : super(context, attrs, defStyleAttr) {
        setOnclickListener()
    }

    interface Callback {
        fun callback()
    }

    private var mCallback: Callback? = null
    fun setCallback(callback: Callback) {
        mCallback = callback
    }

    private fun setOnclickListener() {
        mClick = object : OnClickListener {
            override fun click() {
                text = null
                mCallback?.callback()
            }
        }
    }
}